using UnityEngine;
using System.Collections;
using XML;

public class HUDLoader : MonoBehaviour {

    public TextMesh text3d;

    private Camera _camHUD;
    private GameObject _anchorLeftUp;
    private GameObject _anchorLeftDown;
    private GameObject _anchorRightDown;
    private GameObject _anchorRightUp;
    private float _totalWidth;
    private float _totalHeight;



	// Use this for initialization
	void Start () {

        _camHUD = Camera.allCameras[1];

        InterfaceCreator.SetParameters(_camHUD, this.transform);

        DeserializeHudElement(Const.PATH_XML + "posHUD");

        this.GetComponent<HUD>().Init();
	}


    void DeserializeHudElement(string path)
    {
        TextAsset txt = (TextAsset)Resources.Load(path);

        InStream stream = new InStream(txt.text);

        DeserializeHUD(stream);
    }

    //Deserialize left panel interface
    void DeserializeHUD(InStream stream)
    {

        string name;
        Vector3 pos;
        float height;
        string snap = "";
        
                //Buttons
        stream.List("button", delegate(InStream stream2)
                {
                    snap = "";
                    stream2.Attribute("name", out name);
                    stream2.Content("position", out pos);
                    stream2.Content("height", out height);
                    stream2.ContentOptional("snap", ref snap);

                    InterfaceCreator.CreateButton(name, this.transform, pos, height, true, snap);
                                       

                });

                //Text
        stream.List("text", delegate(InStream stream2)
                {
                    snap = "";
                    stream2.Attribute("name", out name);
                    stream2.Content("position", out pos);
                    stream2.Content("height", out height);
                    stream2.ContentOptional("snap", ref snap);

                    InterfaceCreator.CreateText(name, this.transform, pos, height, snap);
                });

                //Texture
        stream.List("texture", delegate(InStream stream2)
                {
                    snap = "";
                    stream2.Attribute("name", out name);
                    stream2.Content("position", out pos);
                    stream2.Content("height", out height);
                    stream2.ContentOptional("snap", ref snap);

                    InterfaceCreator.CreateTexturePanel(name, this.transform, pos, height, true, snap);
                });

    }


    


}

